-- dark_force
-- created by zhuangsl
-- 黑暗原力（黑武士专属技）

return {
    apply = function(source, target, skillId, round, para, extra)
        if SkillM.immunitySkill(source, target, skillId) then
            -- 目标有免疫专属技属性
            if not SkillM.getSequence(target) then
                SkillM.initSequence(source, target, skillId);
            end
            SkillM.getSequence(target):immunity(source, target, skillId);
            return {};
        end

        local effectRound = -1;
        if para[4] > 0 then
            effectRound = round + para[4] + 1;
        end

        -- 专属技能等级
        local level;
        extra = extra or {};
        if extra["level"] then
            level = tonumber(extra["level"]);
        else
            local prop = PropM.combine(source, "gain_slime_skill", para[1]);
            level = PropM.apply(prop, 0);
        end

        -- 威力
        local force = para[3];

        -- 作用效果
        local valueAttack = 300 + force * level;
        local valueHp = 100 + force * level;

        -- 斯巴达专属加成
        local prop = PropM.combine(source, "battle_cry", 1);
        if prop[3] > 0 then
            -- 触发特技发动事件
            EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });
        end
        valueAttack = PropM.apply(prop, valueAttack);
        valueHp = PropM.apply(prop, valueHp);

        -- 降低生命不允许超过90%
        valueHp = math.min(valueHp, 900);

        -- 如果是boss
        if target:isBoss() then
            valueAttack = math.modf(valueAttack / 2);
            valueHp = math.modf(valueHp / 2);
        end

        -- 先附加状态
        local condition = {
            ["attack"] = valueAttack,
            ["hp"] = valueHp,
            ["end_round"] = effectRound,
        };
        CombatStatusM.applyStatus(target, "dark_force", condition);

        -- 血量减少
        local currHp = target:getHp("hp");
        local reduceHp = math.modf(currHp * valueHp / 1000);
        target:setRealHp(currHp - reduceHp);

        -- 返回作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), tonumber(arr[2]), tonumber(arr[3]), tonumber(arr[4]), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        -- 专属技能等级
        local prop = PropM.combine(source, "gain_slime_skill", para[1]);
        local level = PropM.apply(prop, 0);

        -- 威力
        local force = para[3];

        -- 作用效果
        local valueAttack = 300 + force * level;
        local valueHp = 100 + force * level;

        -- 计算加成
        local addonRate = 0;

        valueAttack = math.modf(valueAttack * (addonRate + 1000) / 1000);
        valueHp = math.modf(valueHp * (addonRate + 1000) / 1000);

        -- 斯巴达专属加成
        prop = PropM.combine(source, "battle_cry", 1);
        valueAttack = PropM.apply(prop, valueAttack);
        valueHp = PropM.apply(prop, valueHp);

        -- 降低生命不允许超过90%
        valueHp = math.min(valueHp, 900);

        desc = string.gsub(desc, "{attack}", valueAttack / 10);
        desc = string.gsub(desc, "{hp}", valueHp / 10);

        -- 回合数
        local round = para[4];
        desc = string.gsub(desc, "{round}", round);

        return desc;
    end,
};
